package com.objcat.playground.leetcode;

/**
 * description: Solution22 <br>
 * date: 2022/3/15 12:30 PM <br>
 * author: objcat <br>
 * version: 1.0 <br>
 */
public class Solution25 {

    /**
     * description: 递归法 <br>
     * version: 1.0 <br>
     * date: 2022/3/18 12:47 PM <br>
     * author: objcat <br>
     * @param root
     * @return int
     * 执行用时：0 ms, 在所有 Java 提交中击败了 100 % 的用户
     * 内存消耗：40.8 MB, 在所有 Java 提交中击败了 57.72 % 的用户
     */
    public int maxDepth(TreeNode root) {
        return root == null ? 0 : Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
    }


    public static void main(String[] args) throws InterruptedException {

        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(2);
        TreeNode treeNode3 = new TreeNode(3);
        TreeNode treeNode4 = new TreeNode(4);
        TreeNode treeNode5 = new TreeNode(5);

        treeNode1.left = treeNode2;
        treeNode1.right = treeNode3;
        treeNode2.left = treeNode4;
        treeNode2.right = treeNode5;

        Solution25 solution25 = new Solution25();
        System.out.println(solution25.maxDepth(treeNode1));
    }
}
